{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Basic Julia Tutorial"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Running/Installing Julia\n",
    "\n",
    "1. To run Julia without a local installation, use (for instance) [CoCalc](https://cocalc.com).\n",
    "\n",
    "2. To install Julia (plus an editor and key packages) on your machine, download and install [JuliaPro](https://juliacomputing.com/products/juliapro.html). \n",
    "\n",
    "3. Alternatively, [download Julia](https://julialang.org/downloads/) and install. You may also want to use the Atom editor with the [Juno IDE](http://junolab.org/). To run IJulia with either jupyter or nteract from your local installation, see [IJulia](https://github.com/JuliaLang/IJulia.jl) for instructions."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Documentation and Help\n",
    "\n",
    "1.  Cheat sheet at [QuantEcon](https://cheatsheets.quantecon.org/julia-cheatsheet.html)\n",
    "2.  [Wiki book](https://en.wikibooks.org/wiki/Introducing_Julia)\n",
    "3.  [ThinkJulia](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html) is a free on-line book\n",
    "4.  The [official Julia on-line manual](https://docs.julialang.org)\n",
    "5.  Discussion lists are found at\n",
    "    *  https://discourse.julialang.org/\n",
    "    *  https://stackoverflow.com/questions/tagged/julia-lang\n",
    "    *  https://www.reddit.com/r/Julia/\n",
    "    *  https://gitter.im/JuliaLang/julia\n",
    "6. In Julia, do ```? cos``` to get help with the cos function    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# About Notebooks\n",
    "\n",
    "This cell is a \"Markdown\" cell. This is meant for comments and documentation, not computations.\n",
    "\n",
    "You can change a cell to \"Code\" or \"Markdown\" in the menu.\n",
    "\n",
    "Markdown cells can handle LaTeX. An example: $\\alpha = \\beta/2$. A Markdown cell can also contain some *formatting*, like lists of this kind\n",
    "\n",
    "1. To insert a new cell, use the menu. \n",
    "\n",
    "2. The next cell is \"Code\". You can run it. Text after a # sign is treated as a comment.\n",
    "\n",
    "3. The subsequent cell shows how to get help on a command."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = 2                  #this is a comment\n",
    "                       #run this cell by using the menu, or by Shift+Enter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "search: \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mh \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mc \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mpi a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mh a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22mn\u001b[0m\u001b[1ms\u001b[22mt \u001b[0m\u001b[1mc\u001b[22ml\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22me\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/latex": [
       "\\begin{verbatim}\n",
       "cos(x)\n",
       "\\end{verbatim}\n",
       "Compute cosine of \\texttt{x}, where \\texttt{x} is in radians.\n",
       "\n",
       "\\rule{\\textwidth}{1pt}\n",
       "\\begin{verbatim}\n",
       "cos(A::AbstractMatrix)\n",
       "\\end{verbatim}\n",
       "Compute the matrix cosine of a square matrix \\texttt{A}.\n",
       "\n",
       "If \\texttt{A} is symmetric or Hermitian, its eigendecomposition (\\href{@ref}{\\texttt{eigen}}) is used to compute the cosine. Otherwise, the cosine is determined by calling \\href{@ref}{\\texttt{exp}}.\n",
       "\n",
       "\\section{Examples}\n",
       "\\begin{verbatim}\n",
       "julia> cos(fill(1.0, (2,2)))\n",
       "2×2 Array{Float64,2}:\n",
       "  0.291927  -0.708073\n",
       " -0.708073   0.291927\n",
       "\\end{verbatim}\n"
      ],
      "text/markdown": [
       "```\n",
       "cos(x)\n",
       "```\n",
       "\n",
       "Compute cosine of `x`, where `x` is in radians.\n",
       "\n",
       "---\n",
       "\n",
       "```\n",
       "cos(A::AbstractMatrix)\n",
       "```\n",
       "\n",
       "Compute the matrix cosine of a square matrix `A`.\n",
       "\n",
       "If `A` is symmetric or Hermitian, its eigendecomposition ([`eigen`](@ref)) is used to compute the cosine. Otherwise, the cosine is determined by calling [`exp`](@ref).\n",
       "\n",
       "# Examples\n",
       "\n",
       "```jldoctest\n",
       "julia> cos(fill(1.0, (2,2)))\n",
       "2×2 Array{Float64,2}:\n",
       "  0.291927  -0.708073\n",
       " -0.708073   0.291927\n",
       "```\n"
      ],
      "text/plain": [
       "\u001b[36m  cos(x)\u001b[39m\n",
       "\n",
       "  Compute cosine of \u001b[36mx\u001b[39m, where \u001b[36mx\u001b[39m is in radians.\n",
       "\n",
       "  ────────────────────────────────────────────────────────────────────────────\n",
       "\n",
       "\u001b[36m  cos(A::AbstractMatrix)\u001b[39m\n",
       "\n",
       "  Compute the matrix cosine of a square matrix \u001b[36mA\u001b[39m.\n",
       "\n",
       "  If \u001b[36mA\u001b[39m is symmetric or Hermitian, its eigendecomposition (\u001b[36meigen\u001b[39m) is used to\n",
       "  compute the cosine. Otherwise, the cosine is determined by calling \u001b[36mexp\u001b[39m.\n",
       "\n",
       "\u001b[1m  Examples\u001b[22m\n",
       "\u001b[1m  ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n",
       "\n",
       "\u001b[36m  julia> cos(fill(1.0, (2,2)))\u001b[39m\n",
       "\u001b[36m  2×2 Array{Float64,2}:\u001b[39m\n",
       "\u001b[36m    0.291927  -0.708073\u001b[39m\n",
       "\u001b[36m   -0.708073   0.291927\u001b[39m"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "? cos                  #to get help on the cos() function"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Load Packages and Extra Functions\n",
    "\n",
    "There are many packages for Julia, for instance, for plotting or statistical methods (see http://pkg.julialang.org/ for a list). To install a package, you do either \n",
    "\n",
    "1. (works everywhere) run `import Pkg` and then `Pkg.add(\"Packagename\")`\n",
    "\n",
    "2. (works in the Julia console, REPL) enter the \"package manager mode\" by typing `]`, then run `add PackageName`. You leave the package manager mode by ctrl-c or backspace.\n",
    "\n",
    "Once a package is installed, you can use it by running\n",
    "\n",
    "```\n",
    "using PackageName\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "printyellow (generic function with 1 method)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "using Dates\n",
    "\n",
    "include(\"printmat.jl\")      #just a function for prettier matrix printing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "using Plots                 #this loads the Plots package\n",
    "\n",
    "#pyplot(size=(600,400))    #choice of plotting backend\n",
    "gr(size=(480,320))\n",
    "default(fmt = :svg)        #try :png or :svg"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Scalars and Matrices\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Create a Scalar and a Matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "q is a scalar. To print, use println() or printlnPs()\n",
      "1\n",
      "\n",
      "Q is a matrix. To print, use display() or printmat()\n",
      "         1         2         3\n",
      "         4         5         6\n",
      "\n"
     ]
    }
   ],
   "source": [
    "q = 1                             #create a scalar\n",
    "Q = [ 1 2 3;                      #create 2x3 matrix\n",
    "      4 5 6 ] \n",
    "println(\"q is a scalar. To print, use println() or printlnPs()\")\n",
    "println(q)\n",
    "\n",
    "println(\"\\nQ is a matrix. To print, use display() or printmat()\")\n",
    "printmat(Q)                       #case sensitive (q and Q are different)\n",
    "                                  #the \\n adds a line break   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Picking Out Parts of a Matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "element [1,2] of Q: 2\n",
      "\n",
      "columns 2 and 3 of Q: \n",
      "         2         3\n",
      "         5         6\n",
      "\n",
      "\n",
      "line 1 of Q (as a vector): \n",
      "         1\n",
      "         2\n",
      "         3\n",
      "\n"
     ]
    }
   ],
   "source": [
    "println(\"\\n\",\"element [1,2] of Q: \",            #commands continue on\n",
    "        Q[1,2])                                 #the next line (until finished)\n",
    "\n",
    "println(\"\\ncolumns 2 and 3 of Q: \")\n",
    "printmat(Q[:,2:3])\n",
    "\n",
    "println(\"\\nline 1 of Q (as a vector): \")\n",
    "printmat(Q[1,:])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Basic Linear Algebra\n",
    "\n",
    "The syntax for linear algebra is similar to the standard text book approach. For instance, \n",
    "* `Q'Q` (or `Q'*Q`) multiplies the transpose ($Q'$) with the matrix ($Q$)\n",
    "* `A*B` does matrix multiplication\n",
    "* `100*Q` multiplies each element of the matrix ($Q$) by 100\n",
    "\n",
    "However, to add a scalar to each element of a matrix, use `100 .+ Q`. Notice the dot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "transpose of Q:\n",
      "         1         4\n",
      "         2         5\n",
      "         3         6\n",
      "\n",
      "Q'Q:\n",
      "        17        22        27\n",
      "        22        29        36\n",
      "        27        36        45\n",
      "\n",
      "scalar * matrix:\n",
      "       100       200       300\n",
      "       400       500       600\n",
      "\n",
      "scalar .+ matrix:\n",
      "       101       102       103\n",
      "       104       105       106\n",
      "\n"
     ]
    }
   ],
   "source": [
    "println(\"transpose of Q:\")\n",
    "printmat(Q')\n",
    "\n",
    "println(\"Q'Q:\")\n",
    "printmat(Q'Q)\n",
    "\n",
    "println(\"scalar * matrix:\")\n",
    "printmat(100*Q)\n",
    "\n",
    "println(\"scalar .+ matrix:\")        #notice the dot\n",
    "printmat(100 .+ Q)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Creating a Sequence and a Vector"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "θ is a sequence: 1:10:21\n",
      "\n",
      "ρ is a vector: \n",
      "         1\n",
      "        11\n",
      "        21\n",
      "\n"
     ]
    }
   ],
   "source": [
    "θ = 1:10:21                  #a sequence (range), type \\theta + TAB to get this symbol        \n",
    "println(\"\\n\",\"θ is a sequence: \",θ)\n",
    "\n",
    "ρ = collect(θ)               #make the sequence into a vector, \\rho+TAB\n",
    "println(\"\\n\",\"ρ is a vector: \")\n",
    "printmat(ρ)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Comparing Things\n",
    "\n",
    "To see if the scalar z <= 0, do \n",
    "```\n",
    "vv = z <= 0\n",
    "```\n",
    "to get a single output (true or false).\n",
    "\n",
    "Instead, if x is an array, do \n",
    "```\n",
    "vv = x .<= 0                      #notice the dot.\n",
    "```\n",
    "to get an array of outputs (same dimension as x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x values: \n",
      "    -1.500\n",
      "    -1.000\n",
      "    -0.500\n",
      "     0.000\n",
      "     0.500\n",
      "\n",
      "true if x is in (-1,0]: \n",
      "         0\n",
      "         0\n",
      "         1\n",
      "         1\n",
      "         0\n",
      "\n",
      "x values that are in (-1,0]: \n",
      "    -0.500\n",
      "     0.000\n",
      "\n"
     ]
    }
   ],
   "source": [
    "x =  [-1.5,-1.0,-0.5,0,0.5]             #this is a vector\n",
    "\n",
    "println(\"x values: \")\n",
    "printmat(x)\n",
    "\n",
    "vv = -1 .< x .<= 0                      #true for x values (-1,0], vv is a vector\n",
    "println(\"true if x is in (-1,0]: \")\n",
    "printmat(vv)\n",
    "\n",
    "x2 = x[vv]                              #x values for which vv==true\n",
    "println(\"x values that are in (-1,0]: \")\n",
    "printmat(x2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Finding Things\n",
    "\n",
    "can be done by, for instance, `findfirst()`, `findall()` and `indexin()`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x values: \n",
      "    -1.500\n",
      "    -1.000\n",
      "    -0.500\n",
      "     0.000\n",
      "     0.500\n",
      "\n",
      "(first) index v in x such x[v]==0: 4\n",
      "\n",
      "all indices v in x such x[v]>=0: \n",
      "         4\n",
      "         5\n",
      "\n",
      "\n",
      "indices in x so that x[v] equals the vector y=[-1.0, 0.0]: \n",
      "         2\n",
      "         4\n",
      "\n"
     ]
    }
   ],
   "source": [
    "x =  [-1.5,-1.0,-0.5,0,0.5]             #this is a vector\n",
    "\n",
    "println(\"x values: \")\n",
    "printmat(x)\n",
    "\n",
    "v1 = findfirst(x.==0)\n",
    "println(\"(first) index v in x such x[v]==0: \",v1)\n",
    "\n",
    "v2 = findall(x.>=0)\n",
    "println(\"\\nall indices v in x such x[v]>=0: \")\n",
    "printmat(v2)\n",
    "\n",
    "y = [-1.0,0]\n",
    "v3 = indexin(y,x)\n",
    "println(\"\\nindices in x so that x[v] equals the vector y=$y: \")\n",
    "printmat(v3)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# if-elseif-else\n",
    "\n",
    "allows you to run different commands depending on a condition which you specify.\n",
    "\n",
    "(extra) There are also two other (more compact) possibilities for the `if-else` case (no `elseif`). In the example below, we actually calculate `y=minimum(z,2)`:\n",
    "\n",
    "1. `y = ifelse(z <= 2,z,2)` or \n",
    "2.  `z <= 2 ? y = z : y = 2`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.05\n"
     ]
    }
   ],
   "source": [
    "z = 1.05\n",
    "\n",
    "if 1 <= z <= 2          #(a) if true, run the next command (y=z) and then jump to end\n",
    "    y = z\n",
    "elseif z < 1            #(b) if (a) is false, try this instead  \n",
    "    y = 1\n",
    "else                    #(c) if also (b) is false, do this\n",
    "    y = 2\n",
    "end\n",
    "\n",
    "println(y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Loops\n",
    "\n",
    "The are two types of loops: \"for loops\" and \"while loops\". \n",
    "\n",
    "The *for loop* is best when you know how many times you want to loop (for instance, over all $m$ rows in a matrix). \n",
    "\n",
    "The *while loop* is best when you want to keep looping until something happens, for instance, that $x_0$ and $x_1$ get really close.\n",
    "\n",
    "The default behaviour in *IJulia* and *inside functions* is that assignments of `x` inside the loop overwrites `x` defined before the loop. To get the same behavior in the REPL (for instance, when you do `include(\"myscript.jl\")` at the Julia prompt), you need to add `global x` somewhere inside the loop.\n",
    "\n",
    "To make sure that the `y` calculated inside the loop does not affect `y` outside the loop, add `local y`.\n",
    "\n",
    "A variable (here `z2`) that does not exist before the loop is local to the loop."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A Simple \"for loop\"\n",
    "\n",
    "The \"for loop\" in the next cell makes 3 iterations and changes a global $x$ variable."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "i=3, x=3 and z2=-998\n",
      "i=6, x=9 and z2=-998\n",
      "i=9, x=18 and z2=-998\n",
      "\n",
      "After loop: x=18 and y=-999\n"
     ]
    }
   ],
   "source": [
    "x = 0\n",
    "y = -999\n",
    "for i = 3:3:9                         #first i=3, then i=6, and last i=9, try also i=1:9\n",
    "    #global x                         #only needed in REPL/scripts\n",
    "    local y                           #don't overwrite y outside loop\n",
    "    x = x + i                         #adding i to the \"old\" x\n",
    "    y = i\n",
    "    z2 = -998                         #notice: z2 has not been used before \n",
    "    println(\"i=$i, x=$x and z2=$z2\")          #$x prints the value of x\n",
    "end\n",
    "\n",
    "println(\"\\nAfter loop: x=$x and y=$y\")\n",
    "#println(z2)            #does not work: z2 is local to the loop"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### A Double \"for loop\"\n",
    "\n",
    "An example of a nested for for loop\n",
    "\n",
    "```\n",
    "for j = 1:n, i = 1:m         \n",
    "    #do something\n",
    "end\n",
    "```\n",
    "\n",
    "If you prefer, could also write a longer version to do the same thing\n",
    "```\n",
    "for j = 1:n \n",
    "    for i = 1:m         \n",
    "        #do something\n",
    "    end    \n",
    "end\n",
    "```\n",
    "\n",
    "The next cell uses a double loop to fill a matrix. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "new x matrix: \n",
      "\n",
      "        11        12        13\n",
      "        21        22        23\n",
      "        31        32        33\n",
      "        41        42        43\n",
      "\n"
     ]
    }
   ],
   "source": [
    "(m,n) = (4,3)                     #same as m=4;n=3\n",
    "x = fill(-999,(m,n))              #to put results in, initialized as -999\n",
    "for i = 1:m, j = 1:n\n",
    "    x[i,j] = 10*i + j\n",
    "end\n",
    "\n",
    "println(\"new x matrix: \\n\") \n",
    "printmat(x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## A Simple \"while loop\"\n",
    "\n",
    "The \"while loop\" in the next cell iterates until two variables ($x_0$ and $x_1$) get close.\n",
    "\n",
    "The background to the example is that we want to solve a function $f(x)=x^2$ for the $x$ value that makes $f(x)=2$. The Newton-Raphson algorithm starts with a value $x_0$ and updates it to\n",
    "$\n",
    "x_1 = x_0 + (2-f(x_0))/f'(x_0)\n",
    "$\n",
    "where $f'(x_0)$ is the derivative of $f()$ evaluated at $x_0$. The algorithm iterates until $x_0$ and $x_1$ are close. Clearly, we are trying to find the square root of 2."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Solving x^2 = 2 with Newton-Raphson:\n",
      "\n",
      "        10 is changed to      5.100\n",
      "     5.100 is changed to      2.746\n",
      "     2.746 is changed to      1.737\n",
      "     1.737 is changed to      1.444\n",
      "     1.444 is changed to      1.415\n",
      "     1.415 is changed to      1.414\n",
      "\n",
      "The result x₁=1.4142135968022693 should be close to      1.414\n"
     ]
    }
   ],
   "source": [
    "println(\"Solving x^2 = 2 with Newton-Raphson:\\n\")\n",
    "\n",
    "x₀ = Inf         #x\\_0 + TAB\n",
    "x₁ = 10\n",
    "\n",
    "while abs(x₁-x₀) > 0.001            #keep going until they get similar\n",
    "    #global x₀, x₁                  #only needed in REPL/script\n",
    "    local y, dy                     #don't overwrite any y,dy outside loop\n",
    "    x₀ = x₁                         #initial guess is taken from old guess\n",
    "    y  = x₀^2                       #value of function\n",
    "    dy = 2*x₀                       #derivative of function\n",
    "    x₁ = x₀ + (2 - y)/dy            #updating the guess, Newton-Raphson\n",
    "    printlnPs(x₀,\" is changed to \",x₁)\n",
    "end\n",
    "\n",
    "printlnPs(\"\\nThe result x₁=$x₁ should be close to \",sqrt(2))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A Simple Function\n",
    "\n",
    "The next cell defines a new function, `fn1()`. It takes a scalar input (`x`) and returns a scalar output (`y`).\n",
    "\n",
    "If you instead use a vector as the input, then the computation fails. (The reason is that you cannot do x^2 on a vector. You could on a square matrix, though.)\n",
    "\n",
    "However, using the \"dot\" syntax\n",
    "```\n",
    "y = fn1.(x)\n",
    "```\n",
    "gives an array as output where element `y[i,j] = fn1(x[i,j])`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "fn1 (generic function with 1 method)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "function fn1(x)               #define a new function \n",
    "  y = (x-1.1)^2 - 0.5\n",
    "  return y\n",
    "end"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "result from fn1(1.5):     -0.340\n",
      "\n",
      "result from fn1.(x): \n",
      "    -0.490\n",
      "    -0.340\n",
      "\n"
     ]
    }
   ],
   "source": [
    "y = fn1(1.5)\n",
    "printlnPs(\"result from fn1(1.5): \",y)\n",
    "\n",
    "x = [1;1.5]\n",
    "#y = fn1(x)                   #would give an error \n",
    "y = fn1.(x)                   #calling on the function, dot. to do for each element in x\n",
    "printlnPs(\"\\nresult from fn1.(x): \")\n",
    "printmat(y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# A First Plot\n",
    "\n",
    "With the Plots package you create a a simple plot like this:\n",
    "\n",
    "1. Plot two curve by using the `plot([x1 x2],[y1 y2])` command\n",
    "2. Configure curves by `linecolor =`, `linestyle =` etc\n",
    "2. Add titles and labels by `title = `, `xlabel = `, etc\n",
    "\n",
    "Notice: the *first plot is slow*."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
       "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"480\" height=\"320\" viewBox=\"0 0 1920 1280\">\n",
       "<defs>\n",
       "  <clipPath id=\"clip4400\">\n",
       "    <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip4400)\" d=\"\n",
       "M0 1280 L1920 1280 L1920 0 L0 0  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip4401\">\n",
       "    <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<path clip-path=\"url(#clip4400)\" d=\"\n",
       "M199.218 1103.18 L1872.76 1103.18 L1872.76 123.472 L199.218 123.472  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<defs>\n",
       "  <clipPath id=\"clip4402\">\n",
       "    <rect x=\"199\" y=\"123\" width=\"1675\" height=\"981\"/>\n",
       "  </clipPath>\n",
       "</defs>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  422.598,1103.18 422.598,123.472 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  774.63,1103.18 774.63,123.472 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1126.66,1103.18 1126.66,123.472 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1478.69,1103.18 1478.69,123.472 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  1830.73,1103.18 1830.73,123.472 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  199.218,1037.29 1872.76,1037.29 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  199.218,846.437 1872.76,846.437 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  199.218,655.584 1872.76,655.584 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  199.218,464.731 1872.76,464.731 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#000000; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
       "  199.218,273.878 1872.76,273.878 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  199.218,1103.18 1872.76,1103.18 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  199.218,1103.18 199.218,123.472 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  422.598,1103.18 422.598,1091.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  774.63,1103.18 774.63,1091.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1126.66,1103.18 1126.66,1091.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1478.69,1103.18 1478.69,1091.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1830.73,1103.18 1830.73,1091.42 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  199.218,1037.29 219.301,1037.29 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  199.218,846.437 219.301,846.437 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  199.218,655.584 219.301,655.584 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  199.218,464.731 219.301,464.731 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  199.218,273.878 219.301,273.878 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip4400)\" d=\"M 0 0 M403.652 1139.37 L416.129 1139.37 L416.129 1143.16 L403.652 1143.16 L403.652 1139.37 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M425.226 1150.32 L441.545 1150.32 L441.545 1154.25 L419.601 1154.25 L419.601 1150.32 Q422.263 1147.56 426.846 1142.93 Q431.453 1138.28 432.633 1136.94 Q434.878 1134.41 435.758 1132.68 Q436.661 1130.92 436.661 1129.23 Q436.661 1126.47 434.716 1124.74 Q432.795 1123 429.693 1123 Q427.494 1123 425.041 1123.77 Q422.61 1124.53 419.832 1126.08 L419.832 1121.36 Q422.656 1120.22 425.11 1119.65 Q427.564 1119.07 429.601 1119.07 Q434.971 1119.07 438.165 1121.75 Q441.36 1124.44 441.36 1128.93 Q441.36 1131.06 440.55 1132.98 Q439.763 1134.88 437.656 1137.47 Q437.077 1138.14 433.976 1141.36 Q430.874 1144.55 425.226 1150.32 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M774.63 1122.77 Q771.019 1122.77 769.19 1126.34 Q767.385 1129.88 767.385 1137.01 Q767.385 1144.11 769.19 1147.68 Q771.019 1151.22 774.63 1151.22 Q778.264 1151.22 780.07 1147.68 Q781.899 1144.11 781.899 1137.01 Q781.899 1129.88 780.07 1126.34 Q778.264 1122.77 774.63 1122.77 M774.63 1119.07 Q780.44 1119.07 783.496 1123.67 Q786.575 1128.26 786.575 1137.01 Q786.575 1145.73 783.496 1150.34 Q780.44 1154.92 774.63 1154.92 Q768.82 1154.92 765.741 1150.34 Q762.686 1145.73 762.686 1137.01 Q762.686 1128.26 765.741 1123.67 Q768.82 1119.07 774.63 1119.07 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1121.31 1150.32 L1137.63 1150.32 L1137.63 1154.25 L1115.69 1154.25 L1115.69 1150.32 Q1118.35 1147.56 1122.94 1142.93 Q1127.54 1138.28 1128.72 1136.94 Q1130.97 1134.41 1131.85 1132.68 Q1132.75 1130.92 1132.75 1129.23 Q1132.75 1126.47 1130.81 1124.74 Q1128.88 1123 1125.78 1123 Q1123.58 1123 1121.13 1123.77 Q1118.7 1124.53 1115.92 1126.08 L1115.92 1121.36 Q1118.75 1120.22 1121.2 1119.65 Q1123.65 1119.07 1125.69 1119.07 Q1131.06 1119.07 1134.25 1121.75 Q1137.45 1124.44 1137.45 1128.93 Q1137.45 1131.06 1136.64 1132.98 Q1135.85 1134.88 1133.75 1137.47 Q1133.17 1138.14 1130.06 1141.36 Q1126.96 1144.55 1121.31 1150.32 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1481.7 1123.77 L1469.9 1142.21 L1481.7 1142.21 L1481.7 1123.77 M1480.48 1119.69 L1486.36 1119.69 L1486.36 1142.21 L1491.29 1142.21 L1491.29 1146.1 L1486.36 1146.1 L1486.36 1154.25 L1481.7 1154.25 L1481.7 1146.1 L1466.1 1146.1 L1466.1 1141.59 L1480.48 1119.69 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1831.13 1135.11 Q1827.98 1135.11 1826.13 1137.26 Q1824.3 1139.41 1824.3 1143.16 Q1824.3 1146.89 1826.13 1149.07 Q1827.98 1151.22 1831.13 1151.22 Q1834.28 1151.22 1836.11 1149.07 Q1837.96 1146.89 1837.96 1143.16 Q1837.96 1139.41 1836.11 1137.26 Q1834.28 1135.11 1831.13 1135.11 M1840.41 1120.46 L1840.41 1124.71 Q1838.65 1123.88 1836.85 1123.44 Q1835.07 1123 1833.31 1123 Q1828.68 1123 1826.22 1126.13 Q1823.79 1129.25 1823.45 1135.57 Q1824.81 1133.56 1826.87 1132.49 Q1828.93 1131.4 1831.41 1131.4 Q1836.62 1131.4 1839.63 1134.58 Q1842.66 1137.72 1842.66 1143.16 Q1842.66 1148.49 1839.51 1151.71 Q1836.36 1154.92 1831.13 1154.92 Q1825.14 1154.92 1821.96 1150.34 Q1818.79 1145.73 1818.79 1137.01 Q1818.79 1128.81 1822.68 1123.95 Q1826.57 1119.07 1833.12 1119.07 Q1834.88 1119.07 1836.66 1119.41 Q1838.47 1119.76 1840.41 1120.46 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M168.074 1023.09 Q164.463 1023.09 162.634 1026.65 Q160.829 1030.19 160.829 1037.32 Q160.829 1044.43 162.634 1048 Q164.463 1051.54 168.074 1051.54 Q171.708 1051.54 173.514 1048 Q175.342 1044.43 175.342 1037.32 Q175.342 1030.19 173.514 1026.65 Q171.708 1023.09 168.074 1023.09 M168.074 1019.38 Q173.884 1019.38 176.94 1023.99 Q180.018 1028.57 180.018 1037.32 Q180.018 1046.05 176.94 1050.66 Q173.884 1055.24 168.074 1055.24 Q162.264 1055.24 159.185 1050.66 Q156.129 1046.05 156.129 1037.32 Q156.129 1028.57 159.185 1023.99 Q162.264 1019.38 168.074 1019.38 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M159.116 829.157 L177.472 829.157 L177.472 833.092 L163.398 833.092 L163.398 841.564 Q164.416 841.217 165.435 841.055 Q166.453 840.87 167.472 840.87 Q173.259 840.87 176.639 844.041 Q180.018 847.212 180.018 852.629 Q180.018 858.207 176.546 861.309 Q173.074 864.388 166.754 864.388 Q164.578 864.388 162.31 864.018 Q160.065 863.647 157.657 862.907 L157.657 858.207 Q159.741 859.342 161.963 859.897 Q164.185 860.453 166.662 860.453 Q170.666 860.453 173.004 858.346 Q175.342 856.24 175.342 852.629 Q175.342 849.018 173.004 846.911 Q170.666 844.805 166.662 844.805 Q164.787 844.805 162.912 845.221 Q161.06 845.638 159.116 846.518 L159.116 829.157 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M133.097 668.929 L140.736 668.929 L140.736 642.563 L132.426 644.23 L132.426 639.97 L140.69 638.304 L145.366 638.304 L145.366 668.929 L153.004 668.929 L153.004 672.864 L133.097 672.864 L133.097 668.929 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M168.074 641.382 Q164.463 641.382 162.634 644.947 Q160.829 648.489 160.829 655.619 Q160.829 662.725 162.634 666.29 Q164.463 669.831 168.074 669.831 Q171.708 669.831 173.514 666.29 Q175.342 662.725 175.342 655.619 Q175.342 648.489 173.514 644.947 Q171.708 641.382 168.074 641.382 M168.074 637.679 Q173.884 637.679 176.94 642.285 Q180.018 646.869 180.018 655.619 Q180.018 664.345 176.94 668.952 Q173.884 673.535 168.074 673.535 Q162.264 673.535 159.185 668.952 Q156.129 664.345 156.129 655.619 Q156.129 646.869 159.185 642.285 Q162.264 637.679 168.074 637.679 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M134.093 478.076 L141.731 478.076 L141.731 451.71 L133.421 453.377 L133.421 449.118 L141.685 447.451 L146.361 447.451 L146.361 478.076 L154 478.076 L154 482.011 L134.093 482.011 L134.093 478.076 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M159.116 447.451 L177.472 447.451 L177.472 451.386 L163.398 451.386 L163.398 459.858 Q164.416 459.511 165.435 459.349 Q166.453 459.164 167.472 459.164 Q173.259 459.164 176.639 462.335 Q180.018 465.506 180.018 470.923 Q180.018 476.502 176.546 479.603 Q173.074 482.682 166.754 482.682 Q164.578 482.682 162.31 482.312 Q160.065 481.941 157.657 481.201 L157.657 476.502 Q159.741 477.636 161.963 478.191 Q164.185 478.747 166.662 478.747 Q170.666 478.747 173.004 476.641 Q175.342 474.534 175.342 470.923 Q175.342 467.312 173.004 465.205 Q170.666 463.099 166.662 463.099 Q164.787 463.099 162.912 463.516 Q161.06 463.932 159.116 464.812 L159.116 447.451 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M136.685 287.223 L153.004 287.223 L153.004 291.158 L131.06 291.158 L131.06 287.223 Q133.722 284.468 138.305 279.839 Q142.912 275.186 144.092 273.843 Q146.338 271.32 147.217 269.584 Q148.12 267.825 148.12 266.135 Q148.12 263.38 146.176 261.644 Q144.255 259.908 141.153 259.908 Q138.954 259.908 136.5 260.672 Q134.069 261.436 131.292 262.987 L131.292 258.265 Q134.116 257.13 136.569 256.552 Q139.023 255.973 141.06 255.973 Q146.43 255.973 149.625 258.658 Q152.819 261.343 152.819 265.834 Q152.819 267.964 152.009 269.885 Q151.222 271.783 149.116 274.376 Q148.537 275.047 145.435 278.265 Q142.333 281.459 136.685 287.223 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M168.074 259.677 Q164.463 259.677 162.634 263.241 Q160.829 266.783 160.829 273.913 Q160.829 281.019 162.634 284.584 Q164.463 288.126 168.074 288.126 Q171.708 288.126 173.514 284.584 Q175.342 281.019 175.342 273.913 Q175.342 266.783 173.514 263.241 Q171.708 259.677 168.074 259.677 M168.074 255.973 Q173.884 255.973 176.94 260.579 Q180.018 265.163 180.018 273.913 Q180.018 282.64 176.94 287.246 Q173.884 291.829 168.074 291.829 Q162.264 291.829 159.185 287.246 Q156.129 282.64 156.129 273.913 Q156.129 265.163 159.185 260.579 Q162.264 255.973 168.074 255.973 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M838.141 12.096 L850.334 12.096 L865.768 53.2532 L881.283 12.096 L893.476 12.096 L893.476 72.576 L885.496 72.576 L885.496 19.4686 L869.9 60.9499 L861.677 60.9499 L846.081 19.4686 L846.081 72.576 L838.141 72.576 L838.141 12.096 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M920.172 76.7889 Q917.012 84.8907 914.014 87.3618 Q911.017 89.8329 905.994 89.8329 L900.039 89.8329 L900.039 83.5945 L904.414 83.5945 Q907.492 83.5945 909.194 82.1361 Q910.895 80.6778 912.961 75.2496 L914.298 71.8468 L895.947 27.2059 L903.847 27.2059 L918.025 62.6918 L932.203 27.2059 L940.102 27.2059 L920.172 76.7889 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1003.3 44.2197 Q1005.93 45.1109 1008.4 48.0275 Q1010.91 50.9442 1013.42 56.0483 L1021.73 72.576 L1012.94 72.576 L1005.2 57.061 Q1002.2 50.9847 999.367 48.9997 Q996.572 47.0148 991.711 47.0148 L982.799 47.0148 L982.799 72.576 L974.616 72.576 L974.616 12.096 L993.088 12.096 Q1003.46 12.096 1008.56 16.4305 Q1013.67 20.7649 1013.67 29.5149 Q1013.67 35.2267 1010.99 38.994 Q1008.36 42.7613 1003.3 44.2197 M982.799 18.8205 L982.799 40.2903 L993.088 40.2903 Q999.002 40.2903 1002 37.5762 Q1005.04 34.8216 1005.04 29.5149 Q1005.04 24.2082 1002 21.5346 Q999.002 18.8205 993.088 18.8205 L982.799 18.8205 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1064.63 48.0275 L1064.63 51.6733 L1030.36 51.6733 Q1030.84 59.3701 1034.97 63.421 Q1039.15 67.4314 1046.56 67.4314 Q1050.85 67.4314 1054.86 66.3781 Q1058.92 65.3249 1062.89 63.2184 L1062.89 70.267 Q1058.87 71.9684 1054.66 72.8596 Q1050.45 73.7508 1046.11 73.7508 Q1035.26 73.7508 1028.9 67.4314 Q1022.58 61.1119 1022.58 50.3365 Q1022.58 39.1965 1028.57 32.6746 Q1034.61 26.1121 1044.82 26.1121 Q1053.97 26.1121 1059.28 32.0264 Q1064.63 37.9003 1064.63 48.0275 M1057.17 45.84 Q1057.09 39.7232 1053.73 36.0774 Q1050.41 32.4315 1044.9 32.4315 Q1038.66 32.4315 1034.89 35.9558 Q1031.17 39.4801 1030.6 45.8805 L1057.17 45.84 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1101.37 28.5427 L1101.37 35.5912 Q1098.21 33.9709 1094.81 33.1607 Q1091.4 32.3505 1087.76 32.3505 Q1082.21 32.3505 1079.41 34.0519 Q1076.66 35.7533 1076.66 39.156 Q1076.66 41.7486 1078.64 43.2475 Q1080.63 44.7058 1086.62 46.0426 L1089.18 46.6097 Q1097.12 48.3111 1100.44 51.4303 Q1103.8 54.509 1103.8 60.0587 Q1103.8 66.3781 1098.78 70.0644 Q1093.79 73.7508 1085.04 73.7508 Q1081.4 73.7508 1077.43 73.0216 Q1073.5 72.3329 1069.12 70.9151 L1069.12 63.2184 Q1073.26 65.3654 1077.27 66.4591 Q1081.28 67.5124 1085.21 67.5124 Q1090.47 67.5124 1093.31 65.73 Q1096.14 63.9071 1096.14 60.6258 Q1096.14 57.5877 1094.08 55.9673 Q1092.05 54.3469 1085.12 52.8481 L1082.53 52.2405 Q1075.6 50.7821 1072.53 47.7845 Q1069.45 44.7463 1069.45 39.4801 Q1069.45 33.0797 1073.98 29.5959 Q1078.52 26.1121 1086.87 26.1121 Q1091 26.1121 1094.64 26.7198 Q1098.29 27.3274 1101.37 28.5427 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1110.85 54.671 L1110.85 27.2059 L1118.3 27.2059 L1118.3 54.3874 Q1118.3 60.8284 1120.81 64.0691 Q1123.32 67.2693 1128.35 67.2693 Q1134.38 67.2693 1137.87 63.421 Q1141.39 59.5726 1141.39 52.9291 L1141.39 27.2059 L1148.85 27.2059 L1148.85 72.576 L1141.39 72.576 L1141.39 65.6084 Q1138.68 69.7404 1135.07 71.7658 Q1131.51 73.7508 1126.77 73.7508 Q1118.95 73.7508 1114.9 68.8897 Q1110.85 64.0286 1110.85 54.671 M1129.6 26.1121 L1129.6 26.1121 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1156.66 9.54393 L1164.12 9.54393 L1164.12 72.576 L1156.66 72.576 L1156.66 9.54393 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1179.31 14.324 L1179.31 27.2059 L1194.66 27.2059 L1194.66 32.9987 L1179.31 32.9987 L1179.31 57.6282 Q1179.31 63.1779 1180.81 64.7578 Q1182.35 66.3376 1187 66.3376 L1194.66 66.3376 L1194.66 72.576 L1187 72.576 Q1178.38 72.576 1175.1 69.3758 Q1171.81 66.1351 1171.81 57.6282 L1171.81 32.9987 L1166.35 32.9987 L1166.35 27.2059 L1171.81 27.2059 L1171.81 14.324 L1179.31 14.324 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1231.4 28.5427 L1231.4 35.5912 Q1228.24 33.9709 1224.84 33.1607 Q1221.44 32.3505 1217.79 32.3505 Q1212.24 32.3505 1209.45 34.0519 Q1206.69 35.7533 1206.69 39.156 Q1206.69 41.7486 1208.68 43.2475 Q1210.66 44.7058 1216.66 46.0426 L1219.21 46.6097 Q1227.15 48.3111 1230.47 51.4303 Q1233.83 54.509 1233.83 60.0587 Q1233.83 66.3781 1228.81 70.0644 Q1223.83 73.7508 1215.08 73.7508 Q1211.43 73.7508 1207.46 73.0216 Q1203.53 72.3329 1199.16 70.9151 L1199.16 63.2184 Q1203.29 65.3654 1207.3 66.4591 Q1211.31 67.5124 1215.24 67.5124 Q1220.51 67.5124 1223.34 65.73 Q1226.18 63.9071 1226.18 60.6258 Q1226.18 57.5877 1224.11 55.9673 Q1222.09 54.3469 1215.16 52.8481 L1212.57 52.2405 Q1205.64 50.7821 1202.56 47.7845 Q1199.48 44.7463 1199.48 39.4801 Q1199.48 33.0797 1204.02 29.5959 Q1208.56 26.1121 1216.9 26.1121 Q1221.03 26.1121 1224.68 26.7198 Q1228.32 27.3274 1231.4 28.5427 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1052.6 1195.6 L1039.71 1212.94 L1053.27 1231.24 L1046.36 1231.24 L1035.99 1217.24 L1025.61 1231.24 L1018.7 1231.24 L1032.55 1212.59 L1019.88 1195.6 L1026.79 1195.6 L1036.24 1208.3 L1045.69 1195.6 L1052.6 1195.6 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M68.7993 824.206 Q64.8526 822.01 62.9747 818.954 Q61.0968 815.899 61.0968 811.761 Q61.0968 806.191 65.0117 803.167 Q68.8948 800.144 76.0881 800.144 L97.6042 800.144 L97.6042 806.032 L76.279 806.032 Q71.1546 806.032 68.672 807.846 Q66.1894 809.66 66.1894 813.384 Q66.1894 817.936 69.2131 820.577 Q72.2368 823.219 77.4567 823.219 L97.6042 823.219 L97.6042 829.108 L76.279 829.108 Q71.1228 829.108 68.672 830.922 Q66.1894 832.736 66.1894 836.524 Q66.1894 841.011 69.2449 843.653 Q72.2686 846.295 77.4567 846.295 L97.6042 846.295 L97.6042 852.183 L61.9562 852.183 L61.9562 846.295 L67.4944 846.295 Q64.216 844.29 62.6564 841.489 Q61.0968 838.688 61.0968 834.837 Q61.0968 830.954 63.0702 828.248 Q65.0436 825.511 68.7993 824.206 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M100.914 779.169 Q107.28 781.651 109.222 784.006 Q111.163 786.362 111.163 790.309 L111.163 794.987 L106.262 794.987 L106.262 791.55 Q106.262 789.131 105.116 787.794 Q103.97 786.457 99.7048 784.834 L97.0312 783.784 L61.9562 798.202 L61.9562 791.995 L89.838 780.855 L61.9562 769.715 L61.9562 763.509 L100.914 779.169 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M66.0621 722.832 Q66.0621 727.543 69.7542 730.28 Q73.4145 733.017 79.812 733.017 Q86.2095 733.017 89.9017 730.312 Q93.5619 727.575 93.5619 722.832 Q93.5619 718.153 89.8698 715.416 Q86.1777 712.679 79.812 712.679 Q73.4781 712.679 69.786 715.416 Q66.0621 718.153 66.0621 722.832 M61.0968 722.832 Q61.0968 715.193 66.0621 710.833 Q71.0273 706.472 79.812 706.472 Q88.5649 706.472 93.5619 710.833 Q98.5272 715.193 98.5272 722.832 Q98.5272 730.503 93.5619 734.863 Q88.5649 739.192 79.812 739.192 Q71.0273 739.192 66.0621 734.863 Q61.0968 730.503 61.0968 722.832 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M83.5359 700.934 L61.9562 700.934 L61.9562 695.078 L83.3131 695.078 Q88.3739 695.078 90.9202 693.104 Q93.4346 691.131 93.4346 687.184 Q93.4346 682.442 90.4109 679.704 Q87.3872 676.935 82.1673 676.935 L61.9562 676.935 L61.9562 671.079 L97.6042 671.079 L97.6042 676.935 L92.1296 676.935 Q95.3762 679.068 96.9676 681.901 Q98.5272 684.701 98.5272 688.425 Q98.5272 694.568 94.7078 697.751 Q90.8883 700.934 83.5359 700.934 M61.0968 686.197 L61.0968 686.197 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M51.8347 659.143 L61.9562 659.143 L61.9562 647.08 L66.5077 647.08 L66.5077 659.143 L85.8594 659.143 Q90.2199 659.143 91.4613 657.966 Q92.7026 656.756 92.7026 653.096 L92.7026 647.08 L97.6042 647.08 L97.6042 653.096 Q97.6042 659.875 95.0897 662.453 Q92.5434 665.031 85.8594 665.031 L66.5077 665.031 L66.5077 669.328 L61.9562 669.328 L61.9562 665.031 L51.8347 665.031 L51.8347 659.143 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M92.257 635.272 L111.163 635.272 L111.163 641.16 L61.9562 641.16 L61.9562 635.272 L67.3671 635.272 Q64.1842 633.426 62.6564 630.625 Q61.0968 627.792 61.0968 623.877 Q61.0968 617.384 66.2531 613.342 Q71.4093 609.268 79.812 609.268 Q88.2147 609.268 93.371 613.342 Q98.5272 617.384 98.5272 623.877 Q98.5272 627.792 96.9994 630.625 Q95.4398 633.426 92.257 635.272 M79.812 615.347 Q73.3508 615.347 69.6905 618.021 Q65.9984 620.662 65.9984 625.309 Q65.9984 629.956 69.6905 632.63 Q73.3508 635.272 79.812 635.272 Q86.2732 635.272 89.9653 632.63 Q93.6256 629.956 93.6256 625.309 Q93.6256 620.662 89.9653 618.021 Q86.2732 615.347 79.812 615.347 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M83.5359 603.73 L61.9562 603.73 L61.9562 597.873 L83.3131 597.873 Q88.3739 597.873 90.9202 595.9 Q93.4346 593.926 93.4346 589.98 Q93.4346 585.237 90.4109 582.5 Q87.3872 579.731 82.1673 579.731 L61.9562 579.731 L61.9562 573.875 L97.6042 573.875 L97.6042 579.731 L92.1296 579.731 Q95.3762 581.863 96.9676 584.696 Q98.5272 587.497 98.5272 591.221 Q98.5272 597.364 94.7078 600.547 Q90.8883 603.73 83.5359 603.73 M61.0968 588.993 L61.0968 588.993 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M51.8347 561.939 L61.9562 561.939 L61.9562 549.876 L66.5077 549.876 L66.5077 561.939 L85.8594 561.939 Q90.2199 561.939 91.4613 560.761 Q92.7026 559.552 92.7026 555.891 L92.7026 549.876 L97.6042 549.876 L97.6042 555.891 Q97.6042 562.671 95.0897 565.249 Q92.5434 567.827 85.8594 567.827 L66.5077 567.827 L66.5077 572.124 L61.9562 572.124 L61.9562 567.827 L51.8347 567.827 L51.8347 561.939 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M61.9562 527.214 L61.9562 521.007 L91.875 509.867 L61.9562 498.727 L61.9562 492.521 L97.6042 505.889 L97.6042 513.846 L61.9562 527.214 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M79.6847 470.177 Q79.6847 477.275 81.3079 480.012 Q82.9312 482.749 86.8461 482.749 Q89.9653 482.749 91.8114 480.712 Q93.6256 478.644 93.6256 475.111 Q93.6256 470.241 90.1881 467.313 Q86.7188 464.353 80.9897 464.353 L79.6847 464.353 L79.6847 470.177 M77.2657 458.496 L97.6042 458.496 L97.6042 464.353 L92.1933 464.353 Q95.4398 466.358 96.9994 469.35 Q98.5272 472.341 98.5272 476.67 Q98.5272 482.145 95.4716 485.391 Q92.3843 488.606 87.2281 488.606 Q81.2125 488.606 78.1569 484.595 Q75.1014 480.553 75.1014 472.564 L75.1014 464.353 L74.5285 464.353 Q70.4862 464.353 68.2901 467.026 Q66.0621 469.668 66.0621 474.474 Q66.0621 477.53 66.7941 480.426 Q67.5262 483.322 68.9903 485.996 L63.5795 485.996 Q62.3381 482.781 61.7334 479.758 Q61.0968 476.734 61.0968 473.869 Q61.0968 466.135 65.1072 462.316 Q69.1176 458.496 77.2657 458.496 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M48.079 452.353 L48.079 446.497 L97.6042 446.497 L97.6042 452.353 L48.079 452.353 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M83.5359 440.959 L61.9562 440.959 L61.9562 435.102 L83.3131 435.102 Q88.3739 435.102 90.9202 433.129 Q93.4346 431.155 93.4346 427.209 Q93.4346 422.466 90.4109 419.729 Q87.3872 416.96 82.1673 416.96 L61.9562 416.96 L61.9562 411.103 L97.6042 411.103 L97.6042 416.96 L92.1296 416.96 Q95.3762 419.092 96.9676 421.925 Q98.5272 424.726 98.5272 428.45 Q98.5272 434.593 94.7078 437.776 Q90.8883 440.959 83.5359 440.959 M61.0968 426.222 L61.0968 426.222 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M78.3161 374.469 L81.1806 374.469 L81.1806 401.396 Q87.2281 401.014 90.4109 397.767 Q93.5619 394.489 93.5619 388.664 Q93.5619 385.29 92.7344 382.139 Q91.9069 378.957 90.2518 375.837 L95.7899 375.837 Q97.1267 378.988 97.827 382.299 Q98.5272 385.609 98.5272 389.014 Q98.5272 397.544 93.5619 402.542 Q88.5967 407.507 80.1303 407.507 Q71.3774 407.507 66.2531 402.796 Q61.0968 398.054 61.0968 390.033 Q61.0968 382.84 65.7438 378.67 Q70.3589 374.469 78.3161 374.469 M76.5973 380.325 Q71.7912 380.389 68.9266 383.031 Q66.0621 385.641 66.0621 389.969 Q66.0621 394.871 68.8312 397.831 Q71.6002 400.759 76.6292 401.205 L76.5973 380.325 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip4402)\" style=\"stroke:#ff0000; stroke-width:8; stroke-opacity:1; fill:none\" points=\"\n",
       "  246.583,414.727 257.25,433.557 267.918,452.106 278.585,470.374 289.253,488.363 299.921,506.07 310.588,523.498 321.256,540.645 331.924,557.511 342.591,574.097 \n",
       "  353.259,590.403 363.926,606.429 374.594,622.174 385.262,637.638 395.929,652.822 406.597,667.726 417.265,682.349 427.932,696.692 438.6,710.754 449.267,724.537 \n",
       "  459.935,738.038 470.603,751.259 481.27,764.2 491.938,776.861 502.606,789.241 513.273,801.34 523.941,813.16 534.608,824.698 545.276,835.957 555.944,846.935 \n",
       "  566.611,857.632 577.279,868.05 587.947,878.186 598.614,888.043 609.282,897.619 619.95,906.914 630.617,915.929 641.285,924.664 651.952,933.118 662.62,941.292 \n",
       "  673.288,949.186 683.955,956.799 694.623,964.131 705.291,971.184 715.958,977.956 726.626,984.447 737.293,990.658 747.961,996.589 758.629,1002.24 769.296,1007.61 \n",
       "  779.964,1012.7 790.632,1017.51 801.299,1022.04 811.967,1026.28 822.634,1030.25 833.302,1033.94 843.97,1037.35 854.637,1040.47 865.305,1043.32 875.973,1045.88 \n",
       "  886.64,1048.17 897.308,1050.17 907.976,1051.9 918.643,1053.34 929.311,1054.51 939.978,1055.39 950.646,1055.99 961.314,1056.32 971.981,1056.36 982.649,1056.12 \n",
       "  993.317,1055.6 1003.98,1054.8 1014.65,1053.72 1025.32,1052.36 1035.99,1050.72 1046.65,1048.8 1057.32,1046.6 1067.99,1044.12 1078.66,1041.36 1089.33,1038.31 \n",
       "  1099.99,1034.99 1110.66,1031.39 1121.33,1027.5 1132,1023.34 1142.66,1018.9 1153.33,1014.17 1164,1009.17 1174.67,1003.88 1185.33,998.313 1196,992.467 \n",
       "  1206.67,986.34 1217.34,979.932 1228,973.245 1238.67,966.277 1249.34,959.028 1260.01,951.499 1270.67,943.69 1281.34,935.6 1292.01,927.23 1302.68,918.579 \n",
       "  1313.35,909.648 1324.01,900.437 1334.68,890.945 1345.35,881.173 1356.02,871.12 1366.68,860.787 1377.35,850.173 1388.02,839.28 1398.69,828.105 1409.35,816.651 \n",
       "  1420.02,804.916 1430.69,792.9 1441.36,780.604 1452.02,768.028 1462.69,755.171 1473.36,742.034 1484.03,728.616 1494.7,714.919 1505.36,700.94 1516.03,686.681 \n",
       "  1526.7,672.142 1537.37,657.323 1548.03,642.223 1558.7,626.842 1569.37,611.181 1580.04,595.24 1590.7,579.019 1601.37,562.517 1612.04,545.734 1622.71,528.671 \n",
       "  1633.37,511.328 1644.04,493.704 1654.71,475.8 1665.38,457.616 1676.04,439.151 1686.71,420.406 1697.38,401.38 1708.05,382.074 1718.72,362.487 1729.38,342.62 \n",
       "  1740.05,322.473 1750.72,302.045 1761.39,281.337 1772.05,260.349 1782.72,239.08 1793.39,217.53 1804.06,195.701 1814.72,173.59 1825.39,151.2 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4402)\" style=\"stroke:#0000ff; stroke-width:4; stroke-opacity:1; fill:none\" stroke-dasharray=\"16, 10\" points=\"\n",
       "  246.583,1075.08 257.25,1074.68 267.918,1074.15 278.585,1073.48 289.253,1072.68 299.921,1071.75 310.588,1070.69 321.256,1069.51 331.924,1068.21 342.591,1066.8 \n",
       "  353.259,1065.28 363.926,1063.66 374.594,1061.94 385.262,1060.13 395.929,1058.23 406.597,1056.26 417.265,1054.22 427.932,1052.12 438.6,1049.96 449.267,1047.75 \n",
       "  459.935,1045.51 470.603,1043.24 481.27,1040.94 491.938,1038.64 502.606,1036.32 513.273,1034.01 523.941,1031.72 534.608,1029.44 545.276,1027.19 555.944,1024.98 \n",
       "  566.611,1022.81 577.279,1020.7 587.947,1018.65 598.614,1016.67 609.282,1014.76 619.95,1012.93 630.617,1011.2 641.285,1009.56 651.952,1008.02 662.62,1006.59 \n",
       "  673.288,1005.27 683.955,1004.07 694.623,1002.99 705.291,1002.04 715.958,1001.22 726.626,1000.53 737.293,999.975 747.961,999.556 758.629,999.277 769.296,999.137 \n",
       "  779.964,999.137 790.632,999.277 801.299,999.556 811.967,999.975 822.634,1000.53 833.302,1001.22 843.97,1002.04 854.637,1002.99 865.305,1004.07 875.973,1005.27 \n",
       "  886.64,1006.59 897.308,1008.02 907.976,1009.56 918.643,1011.2 929.311,1012.93 939.978,1014.76 950.646,1016.67 961.314,1018.65 971.981,1020.7 982.649,1022.81 \n",
       "  993.317,1024.98 1003.98,1027.19 1014.65,1029.44 1025.32,1031.72 1035.99,1034.01 1046.65,1036.32 1057.32,1038.64 1067.99,1040.94 1078.66,1043.24 1089.33,1045.51 \n",
       "  1099.99,1047.75 1110.66,1049.96 1121.33,1052.12 1132,1054.22 1142.66,1056.26 1153.33,1058.23 1164,1060.13 1174.67,1061.94 1185.33,1063.66 1196,1065.28 \n",
       "  1206.67,1066.8 1217.34,1068.21 1228,1069.51 1238.67,1070.69 1249.34,1071.75 1260.01,1072.68 1270.67,1073.48 1281.34,1074.15 1292.01,1074.68 1302.68,1075.08 \n",
       "  1313.35,1075.34 1324.01,1075.45 1334.68,1075.43 1345.35,1075.27 1356.02,1074.96 1366.68,1074.52 1377.35,1073.95 1388.02,1073.23 1398.69,1072.39 1409.35,1071.42 \n",
       "  1420.02,1070.32 1430.69,1069.1 1441.36,1067.76 1452.02,1066.31 1462.69,1064.76 1473.36,1063.1 1484.03,1061.35 1494.7,1059.51 1505.36,1057.59 1516.03,1055.6 \n",
       "  1526.7,1053.54 1537.37,1051.41 1548.03,1049.24 1558.7,1047.02 1569.37,1044.77 1580.04,1042.49 1590.7,1040.19 1601.37,1037.88 1612.04,1035.57 1622.71,1033.26 \n",
       "  1633.37,1030.97 1644.04,1028.7 1654.71,1026.46 1665.38,1024.26 1676.04,1022.12 1686.71,1020.02 1697.38,1017.99 1708.05,1016.03 1718.72,1014.15 1729.38,1012.36 \n",
       "  1740.05,1010.65 1750.72,1009.04 1761.39,1007.54 1772.05,1006.15 1782.72,1004.87 1793.39,1003.71 1804.06,1002.67 1814.72,1001.76 1825.39,1000.98 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip4400)\" d=\"\n",
       "M1525.73 359.632 L1815.16 359.632 L1815.16 178.192 L1525.73 178.192  Z\n",
       "  \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#000000; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
       "  1525.73,359.632 1815.16,359.632 1815.16,178.192 1525.73,178.192 1525.73,359.632 \n",
       "  \"/>\n",
       "<polyline clip-path=\"url(#clip4400)\" style=\"stroke:#ff0000; stroke-width:8; stroke-opacity:1; fill:none\" points=\"\n",
       "  1544.93,238.672 1660.13,238.672 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1695.83 219.934 L1695.83 223.475 L1691.76 223.475 Q1689.46 223.475 1688.56 224.401 Q1687.68 225.327 1687.68 227.735 L1687.68 230.026 L1694.7 230.026 L1694.7 233.337 L1687.68 233.337 L1687.68 255.952 L1683.4 255.952 L1683.4 233.337 L1679.33 233.337 L1679.33 230.026 L1683.4 230.026 L1683.4 228.221 Q1683.4 223.892 1685.41 221.925 Q1687.43 219.934 1691.8 219.934 L1695.83 219.934 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1721.85 240.304 L1721.85 255.952 L1717.59 255.952 L1717.59 240.443 Q1717.59 236.762 1716.15 234.934 Q1714.72 233.105 1711.85 233.105 Q1708.4 233.105 1706.41 235.304 Q1704.42 237.503 1704.42 241.299 L1704.42 255.952 L1700.14 255.952 L1700.14 230.026 L1704.42 230.026 L1704.42 234.054 Q1705.95 231.716 1708.01 230.559 Q1710.09 229.401 1712.8 229.401 Q1717.27 229.401 1719.56 232.179 Q1721.85 234.934 1721.85 240.304 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1727.73 252.017 L1735.37 252.017 L1735.37 225.651 L1727.06 227.318 L1727.06 223.059 L1735.32 221.392 L1740 221.392 L1740 252.017 L1747.64 252.017 L1747.64 255.952 L1727.73 255.952 L1727.73 252.017 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1762.33 219.98 Q1759.23 225.304 1757.73 230.512 Q1756.22 235.721 1756.22 241.068 Q1756.22 246.415 1757.73 251.67 Q1759.26 256.901 1762.33 262.202 L1758.63 262.202 Q1755.16 256.762 1753.42 251.508 Q1751.71 246.253 1751.71 241.068 Q1751.71 235.906 1753.42 230.674 Q1755.14 225.443 1758.63 219.98 L1762.33 219.98 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1766.13 219.98 L1769.83 219.98 Q1773.31 225.443 1775.02 230.674 Q1776.76 235.906 1776.76 241.068 Q1776.76 246.253 1775.02 251.508 Q1773.31 256.762 1769.83 262.202 L1766.13 262.202 Q1769.21 256.901 1770.71 251.67 Q1772.24 246.415 1772.24 241.068 Q1772.24 235.721 1770.71 230.512 Q1769.21 225.304 1766.13 219.98 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip4400)\" style=\"stroke:#0000ff; stroke-width:4; stroke-opacity:1; fill:none\" stroke-dasharray=\"16, 10\" points=\"\n",
       "  1544.93,299.152 1660.13,299.152 \n",
       "  \"/>\n",
       "<path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1699.84 291.502 L1699.84 295.483 Q1698.03 294.488 1696.2 294.002 Q1694.4 293.492 1692.54 293.492 Q1688.4 293.492 1686.11 296.131 Q1683.82 298.747 1683.82 303.492 Q1683.82 308.238 1686.11 310.877 Q1688.4 313.492 1692.54 313.492 Q1694.4 313.492 1696.2 313.006 Q1698.03 312.497 1699.84 311.502 L1699.84 315.437 Q1698.05 316.27 1696.13 316.687 Q1694.23 317.103 1692.08 317.103 Q1686.22 317.103 1682.77 313.423 Q1679.33 309.742 1679.33 303.492 Q1679.33 297.15 1682.8 293.516 Q1686.29 289.881 1692.36 289.881 Q1694.33 289.881 1696.2 290.298 Q1698.08 290.692 1699.84 291.502 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1714.35 293.492 Q1710.92 293.492 1708.93 296.178 Q1706.94 298.84 1706.94 303.492 Q1706.94 308.145 1708.91 310.83 Q1710.9 313.492 1714.35 313.492 Q1717.75 313.492 1719.74 310.807 Q1721.73 308.122 1721.73 303.492 Q1721.73 298.886 1719.74 296.201 Q1717.75 293.492 1714.35 293.492 M1714.35 289.881 Q1719.9 289.881 1723.08 293.492 Q1726.25 297.104 1726.25 303.492 Q1726.25 309.858 1723.08 313.492 Q1719.9 317.103 1714.35 317.103 Q1708.77 317.103 1705.6 313.492 Q1702.45 309.858 1702.45 303.492 Q1702.45 297.104 1705.6 293.492 Q1708.77 289.881 1714.35 289.881 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip4400)\" d=\"M 0 0 M1747.24 291.27 L1747.24 295.298 Q1745.44 294.372 1743.49 293.909 Q1741.55 293.446 1739.46 293.446 Q1736.29 293.446 1734.7 294.418 Q1733.12 295.391 1733.12 297.335 Q1733.12 298.816 1734.26 299.673 Q1735.39 300.506 1738.82 301.27 L1740.27 301.594 Q1744.81 302.566 1746.71 304.349 Q1748.63 306.108 1748.63 309.279 Q1748.63 312.89 1745.76 314.997 Q1742.91 317.103 1737.91 317.103 Q1735.83 317.103 1733.56 316.687 Q1731.32 316.293 1728.82 315.483 L1728.82 311.085 Q1731.18 312.312 1733.47 312.937 Q1735.76 313.539 1738.01 313.539 Q1741.02 313.539 1742.64 312.52 Q1744.26 311.478 1744.26 309.603 Q1744.26 307.867 1743.08 306.941 Q1741.92 306.016 1737.96 305.159 L1736.48 304.812 Q1732.52 303.978 1730.76 302.266 Q1729 300.529 1729 297.52 Q1729 293.863 1731.59 291.872 Q1734.19 289.881 1738.96 289.881 Q1741.32 289.881 1743.4 290.229 Q1745.48 290.576 1747.24 291.27 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /></svg>\n"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x = -3:6/99:6 \n",
    "\n",
    "plot( [x x],[fn1.(x) cos.(x)],\n",
    "      linecolor = [:red :blue],\n",
    "      linestyle = [:solid :dash],\n",
    "      linewidth = [2 1],\n",
    "      label = [\"fn1()\" \"cos\"],\n",
    "      title = \"My Results\",\n",
    "      xlabel = \"x\",\n",
    "      ylabel = \"my output value\" )"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Types: Integers, Floats, Bools and Others\n",
    "\n",
    "Julia has many different types of variables: signed integers (like 2 or -5), floating point numbers (2.0 and -5.1), bools (false/true), bitarrays (similar to bools, but with more efficient use of memory), strings (\"hello\"), Dates (2017-04-23) and many more types."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Integers and Floats"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finding the type of a, b, A and B:\n",
      "Int64 Float64 Array{Int64,1} Array{Float64,1}\n"
     ]
    }
   ],
   "source": [
    "a = 2                   #integer, Int (Int64 on most machines)\n",
    "b = 2.0                 #floating point, (Float64 on most machines)\n",
    "A = [1,2]\n",
    "B = [1.0,2.0]\n",
    "\n",
    "println(\"Finding the type of a, b, A and B:\")\n",
    "println(typeof(a),\" \",typeof(b),\" \",typeof(A),\" \",typeof(B))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Bools and BitArrays\n",
    "\n",
    "Bools are \"true\" or \"false\". BitArrays are (more memory efficient) versions of this."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Finding the type of c and C:\n",
      "Bool BitArray{1}\n"
     ]
    }
   ],
   "source": [
    "c = 2 > 1.1\n",
    "C = A .> 1.5        #A is an array, so C is too\n",
    "\n",
    "println(\"Finding the type of c and C:\")\n",
    "println(typeof(c),\" \",typeof(C))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Calculations with Mixed Types\n",
    "\n",
    "A calculation like \"integer\" + \"float\" works and the type of the result will be a float (the more flexible type). Similarly, \"bool\" + \"integer\" will give an integer. These promotion rules make it easy to have mixed types in calculations, and also provide a simple way of converting a variable from one type to another. (There are also an explicit convert() function that might be quicker.)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.0\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "println(1+2.0)                #integer + Float\n",
    "println((1>0) + 2)            #bool + integer"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Arrays of Arrays (or other types)\n",
    "\n",
    "You can store very different things (a mixture of numbers, matrices, strings) in an array. For instance, if `x1` is a vector and `x2` is a string, then `[x1,x2]` puts them into a vector."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "x[2] is: And Ezra Pound and T.S. Eliot fighting in the captain's tower...\n"
     ]
    }
   ],
   "source": [
    "x1 = 1:10\n",
    "x2 = \"And Ezra Pound and T.S. Eliot fighting in the captain's tower...\"\n",
    "x3 = rand(4,3)\n",
    "x  = [x1,x2,x3]\n",
    "\n",
    "println(\"x[2] is: \",x[2])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "@webio": {
   "lastCommId": null,
   "lastKernelId": null
  },
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Julia 1.4.1",
   "language": "julia",
   "name": "julia-1.4"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.4.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
